package com.yangcangclub.banner.service.impl;

import com.google.common.collect.Maps;
import com.yangcangclub.banner.base.BannerBaseService;
import com.yangcangclub.banner.bean.BannerInfo;
import com.yangcangclub.banner.service.BannerService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/23 0023.
 */
@Service
public class BannerServiceImpl extends BannerBaseService implements BannerService{

    /**
     * 保存
     * @param name
     * @param url
     * @param image
     * @param startDate
     * @param endDate
     * @param createUserId
     * @return
     */
    @Override
    public boolean saveBanner(String name, String url, String image,  String startDate, String endDate, int createUserId) {
        return bannerProfile.insertBanner(name,url,image,startDate,endDate,createUserId);
    }

    /**
     * 编辑
     * @param id
     * @param name
     * @param image
     * @param url
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public boolean editBanner(int id, String name, String image, String url, String startDate, String endDate) {
        return bannerProfile.updateBanner(id,name,image,url,startDate,endDate);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @Override
    public boolean deleteBanner(String ids) {
        return bannerProfile.delBannerByIds(ids);
    }

    /**
     * 移动
     * @param id
     * @param type
     * @param orderSort
     * @return
     */
    @Override
    public boolean moveBanner(int id, String type, int orderSort) {
        return bannerProfile.moveBanner(id,type,orderSort);
    }

    /**
     * 发布&取消发布
     * @param id
     * @param status
     * @param pubUserId
     * @param pubUserName
     * @return
     */
    @Override
    public boolean updateBannerPublishStatus(int id, int status,int pubUserId,String pubUserName) {
        return bannerProfile.updatePublishStatus(id,status,pubUserId,pubUserName);
    }


    /**
     * 前端查询--已发布的Banner
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Map<String, Object> getShowBannerList(int pageNum, int pageSize) {
        Map<String, Object> map= Maps.newHashMap();
        int start=(pageNum-1)*pageSize;
        List<BannerInfo> bannerInfoList = super.bannerProfile.getShowBannerList(start,pageSize);
        map.put("list",bannerInfoList);
        return map;
    }

    /**
     * 后台管理Banner列表
     * @param start
     * @param pageSize
     * @param search
     * @return
     */
    @Override
    public Map<String, Object> getManagerBannerList(int start, int pageSize,String search) {
        Map<String, Object> map= Maps.newHashMap();
        List<BannerInfo> bannerInfoList =super.bannerProfile.getManagerBannerList(start,pageSize,search);
        int total = super.bannerProfile.getManagerBannerNum(start, pageSize, search);
        map.put("rows",bannerInfoList);
        map.put("total",total);
        return map;
    }


}
